/**
 * 企业搜索结果
 * @author  Jello
 * @create  2018/10/23 14:50
 * @version 1.0
 * @company 广东蓝聘科技网络有限公司
 **/
var spinner = new Spinner(opts);

$(function() {
	var userid_sign = sessionStorage.getItem("userid_sign");
	var identity = sessionStorage.getItem("upIdentity");
	if(identity == null) {
		identity = "";
	}
	//获取href中companyName
	var companyName = getParam('companyName');
	//解码
	var searchText = decodeURI(companyName);

	//查询招聘列表
	//查询招聘列表
	var param = {};
	param.identity = identity;
	param.page = 1;
	param.mechanismType = "";
	param.workType = "";
	param.orderType = "";
	param.city = "";
	param.type = 1;
	param.mechanismName = searchText;
	param.userid_sign = userid_sign;
	queryWorkList(param, function(resultObj) {
		$('#worklist').empty();
		$("#query_not_result").css("display", "none");
		//有招聘数据
		if(resultObj.data.workList != null && resultObj.data.workList.length > 0) {
			showWorkData(resultObj);
		} else {
			//没有数据就显示无数据图
			$("#query_not_result").css("display", "block");
		}
	})

});

/**
 * 显示招聘数据
 * @param {Object} resultObj 列表数据
 */
function showWorkData(resultObj) {
	var lendType = ""; //借支
	var isShow = "";
	var workType = ""; //工种
	var workType_isShow1 = "";
	var workType_isShow2 = "";
	var isApply = ""; //是否报名
	var recruitStatus1 = ""; //招工状态
	var recruitStatus2 = "";
	var key = ""; //关键字
	for(var i = 0; i < resultObj.data.workList.length; i++) {
		var lend_type = resultObj.data.workList[i].lendType;
		var post_type = resultObj.data.workList[i].postType;
		if(lend_type == 1) {
			isShow = "block";
			lendType = "可借支";
		} else if(lend_type == 0) {
			isShow = "none";
		}
		if(post_type == 1) {
			workType_isShow2 = "none";
			workType_isShow1 = "block";
			workType = "小时工";
		} else if(post_type == 0) {
			workType = "正式工";
			workType_isShow1 = "none";
			workType_isShow2 = "block";
		}
		if(resultObj.data.workList[i].isApply == 0) {
			isApply = "block";
		} else {
			isApply = "none";
		}
		if(resultObj.data.workList[i].status == 1) {
			recruitStatus1 = "block";
			recruitStatus2 = "none";
		} else {
			recruitStatus1 = "none";
			recruitStatus2 = "block";
		}
		if(resultObj.data.workList[i].key == null) {
			key = "";
		} else {
			key = resultObj.data.workList[i].key;
		}

		var html = '<div class="mui-table-view-celll"><div class="item_box2" onclick="queryWorkDetail(' + resultObj.data.workList[i].id + ')">' +
			'<div class="item_box">' +
			'<div class="box_f">' + resultObj.data.workList[i].mechanismName + '</div>' +
			'<div class="f_jiezi" id="f_jiezi"' + "style=display:" + isShow + "" + '>' + lendType + '</div>' +
			'<div class="box_fs"><span>' + resultObj.data.workList[i].mechanismScore + '</span>分</div>' +
			'<div class="box_b">' +
			'<img class="b_img" style="width: 1.893333rem;height: 1.486666rem;" src="' + resultObj.data.workList[i].mechanismUrl + '" />' +
			'<div class="yibaoming" ' + "style=display:" + isApply + "" + '>已报名</div>' +
			'<div class="b_moneythree">' +
			'<div class="b_money" ' + "style=display:" + workType_isShow2 + "" + '>' + resultObj.data.workList[i].wageRange + '元/月</div>' +
			'<div class="b_money" ' + "style=display:" + workType_isShow1 + "" + '>' + resultObj.data.workList[i].workMoney + '元/小时</div>' +
			'<div class="b_three bthree_key">' +
			'<div class="item_b_box">' + key + '</div>' +
			'</div>' +
			'<div class="b_fore_box">' +
			'<div class="x_width" ' + "style=display:" + recruitStatus1 + "" + '>已招满</div>' +
			'<div class="x_width" ' + "style=display:" + recruitStatus2 + "" + '>需' + resultObj.data.workList[i].workTypeName + '' + resultObj.data.workList[i].maxNumber + '人</div>' +
			'<div>已报名' + resultObj.data.workList[i].applyNumber + '人</div>' +
			'</div>' +
			'</div>' +
			'<div class="b_renyuan">' +
			'<div class="b_money"><span>' + workType + '</span></div>' +
			'</div>' +
			'</div>' +
			'</div>' +
			'</div></div>';

		$('#worklist').append(html);
	}
}

//根据id传详情页面
//根据id传详情页面
function queryWorkDetail(id) {
	window.location.href = "recruitmentlist_detailH5.html?id="+ id;
}